'use strict';
angular.module('app').directive('calendar', ['$state', '$q', function ($state, $q) {
    return {
        restrict: 'A',
        replace: true,
        templateUrl: 'views/integral/child/calendar.html',
        scope: false,
        link: function ($scope, element, attrs) {
            $scope.uplateTimes= function uplateTimes(isSign,myday) {
                $scope.cale= new Calendar("idCalendar", {
                    qdDay: myday,
                    isSignIn:isSign,
                    onToday: function (o) {     //判断当天
                        o.className = "onToday";
                    },
                    onSignIn: function () { //签到

                    },
                    onFinish: function () {
                        $("#idCalendarYear").text(this.Year);
                        $("#idCalendarMonth").text( this.Month);  //表头年份
                    }
                });

            };
           /* $("#idCalendarPre").click(function () {

            })
            $("#idCalendarNext").click(function () {
                $scope.cale.NextMonth();
            })
*/
            $scope.calenderPre=function () {
                $scope.cale.PreMonth();

            }
            $scope.calenderNext=function () {
                $scope.cale.NextMonth();

            }
            /**
             * 刷新数据
             */
            $scope.$watch("signTimes", function (times) {
                var myday = new Array(); //已签到的数组
                if (times) {
                    for (var i = 0; i < times.length; i++) {
                        myday.push((Date.parse(times[i])/1000))
                    }
                }
                $scope.uplateTimes($scope.signing,myday);
            });
            var myday = new Array(); //已签到的数组
            $scope.uplateTimes($scope.signing,myday);

        }
    }

}]);